import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout'
import Home from '@/views/Home'
import User from '@/views/User'
import Search from '@/views/Search'
import SearchResult from '@/views/Search/SearchResult'
import Article from '@/views/Article/articleId'
Vue.use(VueRouter)
const routes = [
  // 打开默认显示界面
  {
    path: '/',
    // 重定向路由到登陆页面
    redirect: '/login'
  },
  // 跳转到登陆页面
  {
    path: '/login',
    component: Login
  },
  // 跳转到搜索页面
  {
    path: '/search',
    component: Search
  },
  // 搜索页面的动态路由切换
  {
    path: '/search/:name', // 动态路由
    component: SearchResult
  },
  // 跳转到home首页
  {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home', // 默认显示二级页面为home首页
    children: [
      // 二路路由的home首页
      {
        path: 'home',
        component: Home
      },
      // 二级路由的个人中心页面
      {
        path: 'user',
        component: User
      }]
  },
  // 跳转到文章详情
  {
    path: '/article',
    component: Article
  }
]

const router = new VueRouter({
  routes
})

export default router
